package com.example.filecabinet.controller;

import com.example.filecabinet.dto.StaffMemberInfo;
import com.example.filecabinet.service.Lattice_infoService;
import com.example.filecabinet.util.QueryFreeFells;
import com.thfdcsoft.framework.common.http.dto.BaseHttpRspn;
import com.thfdcsoft.framework.common.json.jackson.JacksonFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

@Controller
public class IndexController {
    @Autowired
    Lattice_infoService lattice_infoService;

    /**
     * 验证客户端是否连接上业务层
     *
     * @return
     */
    @GetMapping("/index")
    @ResponseBody
    public String index() {
        BaseHttpRspn result = new BaseHttpRspn(true);
        return JacksonFactory.writeJson(result);
    }

    @RequestMapping("/page")
    public String test() {
        return "index";
    }

    @RequestMapping("/over")
    public String over() {
        return "over";
    }

    /**
     * 加载 工作人员取件业务信息页面
     *
     * @return
     */
    @RequestMapping("/staffTakeyw")
    public String staffTakeyw() {
        System.out.println("加载工作人员取件 业务信息页面");

        return "staffTake";
    }

    /**
     * 加载 工作人员存件业务信息页面
     *
     * @return
     */
    @RequestMapping("/staffStoreyw")
    public String staffStoreyw(Model model, String rspn) {
        System.out.println("加载工作人员存件 业务信息页面");
        String staffInfo = null;
        try {
            staffInfo = URLDecoder.decode(rspn, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        StaffMemberInfo staffMemberInfo = JacksonFactory.readJson(staffInfo, StaffMemberInfo.class);

        model.addAttribute("businessNumber", staffMemberInfo.getBusinessNumber());
        model.addAttribute("businessType", staffMemberInfo.getBusinessType());
        return "staffStore";
    }

}
